import Cookies from "js-cookie";

const TokenKey = "access_token";
const IdTokenKey = "id_token";

export function getToken() {
  return Cookies.get(TokenKey);
}

export function setToken(token) {
  return Cookies.set(TokenKey, token);
}

export function removeToken() {
  return Cookies.remove(TokenKey);
}

export function setIdToken(token) {
  return Cookies.set(IdTokenKey, token);
}

export function getIdToken() {
  return Cookies.get(IdTokenKey);
}

export function removeIdToken() {
  return Cookies.remove(IdTokenKey);
}

export function navToAuthor() {
  let authorUrl =
    process.env.VUE_APP_AuthServer +
    "/connect/authorize?client_id=" +
    process.env.VUE_APP_ClientId +
    "&redirect_uri=" +
    encodeURI(process.env.VUE_APP_URL + "/oidc") +
    "&response_type=id_token token&scope=openid roles profile AuthorCenter&state=111&nonce=1234";
  window.location.href = authorUrl;
}

export function navToAuthorLogout() {
  let idToken = getIdToken();
  let logoutUrl =
    process.env.VUE_APP_AuthServer +
    "/connect/logout?id_token_hint=" +
    idToken +
    "&post_logout_redirect_uri=" +
    encodeURI(process.env.VUE_APP_URL + "/oidc_signout");
  window.location.href = logoutUrl;
}
